package p0;

class Leetcode_6 {
    public String convert(String s, int numRows) {
        if (numRows <= 1) {
            return s;
        }
        StringBuilder[] rows = new StringBuilder[numRows];
        for (int i = 0; i < numRows; i++) {
            rows[i] = new StringBuilder();
        }
        char[] sArray = s.toCharArray();
        // 行号是否逆序
        boolean re = true;
        int row = 0;
        for (int i = 0; i < s.length(); i++) {
            rows[row].append(sArray[i]);
            if (row == 0 || row == numRows - 1) {
                re = !re;
            }
            if (re) {
                row--;
            } else {
                row++;
            }
        }
        StringBuilder res = new StringBuilder();
        // 添加到结果
        for (int i = 0; i < numRows; i++) {
            res.append(rows[i]);
        }
        return res.toString();
    }

    public static void main(String[] args) {

    }
}